var numDecodings = function(s) {
    if (s[0] === '0') {
        return 0
    }
    let dp = []
    dp[0] = { value: 1, has: 0 }
    for (let i = 1; i < s.length; i++) {
        let add = parseInt(s[i - 1] + s[i])
        if (s[i] === '0' && (s[i - 1] !== '1' && s[i - 1] !== '2')) {
            return 0
        }
        if (s[i] === '0' && i === 1 && add > 0 && add < 27) {
            dp[i] = { value: 1, has: 1 }
            continue
        }

        if (s[i] === '0') {
            dp[i] = { value: dp[i - 2].value, has: 0 }
        } else {
            if (add > 0 && add < 27 && s[i - 1] !== '0') {
                dp[i] = { value: dp[i - 1].value * 2 - dp[i - 1].has, has: dp[i - 1].value - dp[i - 1].has }
            } else {
                dp[i] = { value: dp[i - 1].value, has: 0 }
            }
        }
    }
    return dp[dp.length - 1].value
};
console.log(numDecodings("2277"))